package com.study.javaOther.Main;


import com.study.javaOther.entity.Organization;
import com.study.javaOther.utils.JdbcUtil;
import com.study.javaOther.utils.PinYinUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @ClassName: Worker
 * @Description:
 * @author: 王胜
 * @date 2021/6/25
 * @Version: 1.0
 **/
public class UpdateWorker implements Runnable {

    static String sql = "update `inf_organization` set name_pinyin=? where id=?";
    List<Organization> list = new ArrayList<>();
    CountDownLatch latch;
    public UpdateWorker(CountDownLatch latch,List list){
        this.latch = latch;
        this.list=list;
    }

    @Override
    public void run() {
        for (Organization item:list) {
            System.out.println("线程："+Thread.currentThread().getName()+"数据 "+item.getId()+ "正在转换...");
            String pinyin= PinYinUtil.getPingYin(item.getName());
            Object[] params = new Object[] { pinyin,item.getId() };
            JdbcUtil.update(sql, params);
        }
        latch.countDown();
    }

}